<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">

            <el-form-item label="任务令" prop="po">
                <el-input v-model="queryParams.po" placeholder="请输入任务令" clearable size="small"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="产品编码" prop="itemNumber">
                <el-input v-model="queryParams.itemNumber" placeholder="请输入产品编码" clearable size="small"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>

            <el-form-item label="产品SN" prop="sn">
                <el-input v-model="queryParams.sn" placeholder="请输入产品SN" clearable size="small"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="回传时间" prop="updatedDate">
                <el-date-picker v-model="dateRange" type="daterange" range-separator="至" start-placeholder="开始日期"
                    end-placeholder="结束日期" value-format="yyyy-MM-dd HH:mm:ss" :default-time="['00:00:00', '23:59:59']">
                </el-date-picker>
            </el-form-item>

            <el-form-item label="打印人名字及工号" prop="createdBy" label-width="130px">
                <el-input v-model="queryParams.createdBy" placeholder="请输入打印人名字及工号" clearable size="small"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>

            <el-form-item label="上传下载标识" prop="uploadFlag" label-width="120px">
                <el-input v-model="queryParams.uploadFlag" placeholder="请输入上传下载标识" clearable size="small"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item>
                <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>
        <el-table v-loading="loading" :data="barcodeAttributeList" @selection-change="handleSelectionChange">
            <el-table-column type="selection" align="center" />
            <el-table-column label="2位EMS代码+8位年月日+流水号" align="center" prop="emsTransId" :show-overflow-tooltip="true"
                width="150" />
            <el-table-column label="非能源默认157" align="center" prop="organizationId" :show-overflow-tooltip="true"
                width="150" />
            <el-table-column label="任务令" align="center" prop="po" width="100" />
            <el-table-column label="产品编码" align="center" prop="itemNumber" width="100" />
            <el-table-column label="写实际打印的版本，若无版本，则为空" align="center" prop="itemVer" :show-overflow-tooltip="true"
                width="150" />
            <el-table-column label="2位供应商代码" align="center" prop="emsCode" :show-overflow-tooltip="true" width="150" />
            <el-table-column label="供应商编码" align="center" prop="vendorId" width="120" />
            <el-table-column label="产品SN" align="center" prop="sn" />
            <el-table-column label="产品二维条码" align="center" prop="barcodeQr" :show-overflow-tooltip="true" width="150" />
            <el-table-column label="产品加工原产地CHINA填写CN" align="center" prop="coo" :show-overflow-tooltip="true"
                width="150" />
            <el-table-column label="回传时间" align="center" prop="updatedDate" />
            <el-table-column label="数制回传人名字及工号" align="center" prop="updatedBy" :show-overflow-tooltip="true"
                width="150" />
            <el-table-column label="产品条码打印时间" align="center" prop="createdDate" :show-overflow-tooltip="true"
                width="150" />
            <el-table-column label="打印人名字及工号" align="center" prop="createdBy" :show-overflow-tooltip="true"
                width="150" />
            <el-table-column label="attribute1" align="center" prop="attribute1" width="100" />
            <el-table-column label="attribute2" align="center" prop="attribute2" width="100" />
            <el-table-column label="attribute3" align="center" prop="attribute3" width="100" />
            <el-table-column label="attribute4" align="center" prop="attribute4" width="100" />
            <el-table-column label="attribute5" align="center" prop="attribute5" width="100" />
            <el-table-column label="segment1" align="center" prop="segment1" :show-overflow-tooltip="true"
                width="100" />
            <el-table-column label="segment2" align="center" prop="segment2" :show-overflow-tooltip="true"
                width="100" />
            <el-table-column label="segment3" align="center" prop="segment3" :show-overflow-tooltip="true"
                width="100" />
            <el-table-column label="segment4" align="center" prop="segment4" :show-overflow-tooltip="true"
                width="100" />
            <el-table-column label="segment5" align="center" prop="segment5" :show-overflow-tooltip="true"
                width="100" />
            <el-table-column label="上传标识" align="center" prop="uploadFlag">
                <template slot-scope="scope">
                    <span>{{
                        scope.row.uploadFlag===0?'待上载':scope.row.uploadFlag===1?'正在上载':scope.row.uploadFlag===2?'上载成功':scope.row.uploadFlag===9?'上载失败':''
                        }}</span>
                </template>
            </el-table-column>
            <el-table-column label="校验信息" align="center" prop="checkMessage" />
            <el-table-column label="型号" align="center" prop="type" />
            <el-table-column label="打印人名字及工号" align="center" prop="roshFlag" :show-overflow-tooltip="true"
                width="150" />
<el-table-column label="华为回传结果" align="center" >
                <template slot-scope="scope">
                    <el-button size="mini" type="text"  @click="handleDetails(scope.row)"> 查看</el-button>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
            @pagination="getList" />
<el-dialog
  title="华为回传结果"
  :visible.sync="dialogVisible"
  width="30%"
  >
  
    {{details.res?JSON.parse(details.res):'暂无'}}

</el-dialog>
    </div>
</template>

<script>
    import { listBarcodeAttribute, getBarcodeAttribute, delBarcodeAttribute, addBarcodeAttribute, updateBarcodeAttribute, exportBarcodeAttribute } from "@/api/ems/barcodeAttribute";

    export default {
        name: "BarcodeAttribute",
        data() {
            return {
                // 遮罩层
                loading: true, dateRange: [],
                // 选中数组
                ids: [],
                // 非单个禁用
                single: true,
                // 非多个禁用
                multiple: true,
                // 显示搜索条件
                showSearch: true,
                // 总条数
                total: 0,
                // 产品条码属性表格数据
                barcodeAttributeList: [],
                // 弹出层标题
                title: "",
                // 是否显示弹出层
                open: false,
                // 查询参数
                queryParams: {
                    pageNum: 1,
                    pageSize: 10,
                    po: undefined,
                    itemNumber: undefined,
                    sn: undefined,
                    createdBy: undefined,
                    uploadFlag: undefined
                },
                // 表单参数
                form: {},
                // 表单校验
                rules: {
                },
                 dialogVisible:false,
                details:{}
            };
        },
        created() {
            this.getList();
        },
        methods: {
             handleDetails(val){
                console.log(11);
this.dialogVisible=true
this.details=val

            },
            /** 查询产品条码属性列表 */
            getList() {
                this.loading = true;
                listBarcodeAttribute(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
                    this.barcodeAttributeList = response.rows;
                    this.total = response.total;
                    this.loading = false;
                });
            },
            // 取消按钮
            cancel() {
                this.open = false;
                this.reset();
            },
            // 表单重置
            reset() {
                this.form = {
                    emsTransId: null,
                    organizationId: null,
                    po: null,
                    itemNumber: null,
                    itemVer: null,
                    emsCode: null,
                    vendorId: null,
                    sn: null,
                    barcodeQr: null,
                    coo: null,
                    updatedDate: null,
                    updatedBy: null,
                    createdDate: null,
                    createdBy: null,
                    attribute1: null,
                    attribute2: null,
                    attribute3: null,
                    attribute4: null,
                    attribute5: null,
                    segment1: null,
                    segment2: null,
                    segment3: null,
                    segment4: null,
                    segment5: null,
                    uploadFlag: null,
                    checkMessage: null,
                    type: null,
                    roshFlag: null
                };
                this.resetForm("form");
            },
            /** 搜索按钮操作 */
            handleQuery() {
                this.queryParams.pageNum = 1;
                this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.dateRange = []
                this.resetForm("queryForm");
                this.handleQuery();
            },
            // 多选框选中数据
            handleSelectionChange(selection) {
                this.ids = selection.map(item => item.emsTransId)
                this.single = selection.length !== 1
                this.multiple = !selection.length
            },
            /** 新增按钮操作 */
            handleAdd() {
                this.reset();
                this.open = true;
                this.title = "添加产品条码属性";
            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.reset();
                const emsTransId = row.emsTransId || this.ids
                getBarcodeAttribute(emsTransId).then(response => {
                    this.form = response.data;
                    this.open = true;
                    this.title = "修改产品条码属性";
                });
            },
            /** 提交按钮 */
            submitForm() {
                this.$refs["form"].validate(valid => {
                    if (valid) {
                        if (this.form.emsTransId != null) {
                            updateBarcodeAttribute(this.form).then(response => {
                                if (response.code === 200) {
                                    this.msgSuccess("修改成功");
                                    this.open = false;
                                    this.getList();
                                }
                            });
                        } else {
                            addBarcodeAttribute(this.form).then(response => {
                                if (response.code === 200) {
                                    this.msgSuccess("新增成功");
                                    this.open = false;
                                    this.getList();
                                }
                            });
                        }
                    }
                });
            },
            /** 删除按钮操作 */
            handleDelete(row) {
                const emsTransIds = row.emsTransId || this.ids;
                this.$confirm('是否确认删除产品条码属性编号为"' + emsTransIds + '"的数据项?', "警告", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                }).then(function () {
                    return delBarcodeAttribute(emsTransIds);
                }).then(() => {
                    this.getList();
                    this.msgSuccess("删除成功");
                }).catch(function () { });
            },
            /** 导出按钮操作 */
            handleExport() {
                const queryParams = this.queryParams;
                this.$confirm('是否确认导出所有产品条码属性数据项?', "警告", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                }).then(function () {
                    return exportBarcodeAttribute(queryParams);
                }).then(response => {
                    this.download(response.msg);
                }).catch(function () { });
            }
        }
    };
</script>